<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Transition guide</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../df/d65/tutorial_table_of_content_introduction.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Transition guide </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#tutorial_transition_overview">Changes overview </a></li>
<li class="level1"><a href="#tutorial_transition_hints">Transition hints </a><ul><li class="level2"><a href="#tutorial_transition_hints_24">Prepare 2.4 </a></li>
<li class="level2"><a href="#tutorial_transition_hints_headers">New headers layout </a></li>
<li class="level2"><a href="#tutorial_transition_algorithm">Modern way to use algorithm </a></li>
<li class="level2"><a href="#tutorial_transition_hints_ml">Machine learning module </a></li>
<li class="level2"><a href="#tutorial_transition_hints_features">Features detect </a></li>
<li class="level2"><a href="#tutorial_transition_hints_opencl">OpenCL </a></li>
<li class="level2"><a href="#tutorial_transition_hints_cuda">CUDA </a></li>
<li class="level2"><a href="#tutorial_transition_docs">Documentation format </a></li>
<li class="level2"><a href="#tutorial_transition_both">Support both versions </a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d4/db1/tutorial_documentation.html">Writing documentation for OpenCV</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../d3/dff/tutorial_cross_referencing.html">Cross referencing OpenCV from other Doxygen projects</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Maksim Shabunin </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.0 </td></tr>
</table>
<h1><a class="anchor" id="tutorial_transition_overview"></a>
Changes overview </h1>
<p>This document is intended to software developers who want to migrate their code to OpenCV 3.0.</p>
<p>OpenCV 3.0 introduced many new algorithms and features comparing to version 2.4. Some modules have been rewritten, some have been reorganized. Although most of the algorithms from 2.4 are still present, the interfaces can differ.</p>
<p>This section describes most notable changes in general, all details and examples of transition actions are in the next part of the document.</p>
<h5>Contrib repository</h5>
<p><a href="https://github.com/opencv/opencv_contrib">https://github.com/opencv/opencv_contrib</a></p>
<p>This is a place for all new, experimental and non-free algorithms. It does not receive so much attention from the support team comparing to main repository, but the community makes an effort to keep it in a good shape.</p>
<p>To build OpenCV with <em>contrib</em> repository, add the following option to your cmake command: </p><div class="fragment"><div class="line">-DOPENCV_EXTRA_MODULES_PATH=&lt;path-to-opencv_contrib&gt;/modules</div></div><!-- fragment --><h5>Headers layout</h5>
<p>In 2.4 all headers are located in corresponding module subfolder (<em>opencv2/&lt;module&gt;/&lt;module&gt;.hpp</em>), in 3.0 there are top-level module headers containing the most of the module functionality: <em>opencv2/&lt;module&gt;.hpp</em> and all C-style API definitions have been moved to separate headers (for example opencv2/core/core_c.h).</p>
<h5>Algorithm interfaces</h5>
<p>General algorithm usage pattern has changed: now it must be created on heap wrapped in smart pointer <a class="el" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">cv::Ptr</a>. Version 2.4 allowed both stack and heap allocations, directly or via smart pointer.</p>
<p><em>get</em> and <em>set</em> methods have been removed from the <a class="el" href="../../d3/d46/classcv_1_1Algorithm.html" title="This is a base class for all more or less complex algorithms in OpenCV. ">cv::Algorithm</a> class along with <em>CV_INIT_ALGORITHM</em> macro. In 3.0 all properties have been converted to the pairs of <em>getProperty/setProperty</em> pure virtual methods. As a result it is <b>not</b> possible to create and use <a class="el" href="../../d3/d46/classcv_1_1Algorithm.html" title="This is a base class for all more or less complex algorithms in OpenCV. ">cv::Algorithm</a> instance by name (using generic <em>Algorithm::create(String)</em> method), one should call corresponding factory method explicitly.</p>
<h5>Changed modules</h5>
<ul>
<li><em>ml</em> module has been rewritten</li>
<li><em>highgui</em> module has been split into parts: <em>imgcodecs</em>, <em>videoio</em> and <em>highgui</em> itself</li>
<li><em>features2d</em> module have been reorganized (some feature detectors has been moved to <em>opencv_contrib/xfeatures2d</em> module)</li>
<li><em>legacy</em>, <em>nonfree</em> modules have been removed. Some algorithms have been moved to different locations and some have been completely rewritten or removed</li>
<li>CUDA API has been updated (<em>gpu</em> module -&gt; several <em>cuda</em> modules, namespace <em>gpu</em> -&gt; namespace <em>cuda</em>)</li>
<li>OpenCL API has changed (<em>ocl</em> module has been removed, separate <em>ocl::</em> implementations -&gt; Transparent API)</li>
<li>Some other methods and classes have been relocated</li>
</ul>
<h1><a class="anchor" id="tutorial_transition_hints"></a>
Transition hints </h1>
<p>This section describes concrete actions with examples.</p>
<h2><a class="anchor" id="tutorial_transition_hints_24"></a>
Prepare 2.4 </h2>
<p>Some changes made in the latest 2.4.11 OpenCV version allow you to prepare current codebase to migration:</p>
<ul>
<li><a class="el" href="../../dc/d84/group__core__basic.html#gaee940caae29d5569aa3aa9ba77fb887f">cv::makePtr</a> function is now available</li>
<li><em>opencv2/&lt;module&gt;.hpp</em> headers have been created</li>
</ul>
<h2><a class="anchor" id="tutorial_transition_hints_headers"></a>
New headers layout </h2>
<p><b>Note:</b> Changes intended to ease the migration have been made in OpenCV 3.0, thus the following instructions are not necessary, but recommended.</p>
<ol type="1">
<li>Replace inclusions of old module headers: <div class="fragment"><div class="line"><span class="comment">// old header</span></div><div class="line"><span class="preprocessor">#include &quot;opencv2/&lt;module&gt;</span>/&lt;module&gt;.hpp<span class="stringliteral">&quot;</span></div><div class="line"><span class="stringliteral">// new header</span></div><div class="line"><span class="stringliteral">#include &quot;</span>opencv2/&lt;module&gt;.hpp<span class="stringliteral">&quot;</span></div></div><!-- fragment --></li>
</ol>
<h2><a class="anchor" id="tutorial_transition_algorithm"></a>
Modern way to use algorithm </h2>
<ol type="1">
<li>Algorithm instances must be created with <a class="el" href="../../dc/d84/group__core__basic.html#gaee940caae29d5569aa3aa9ba77fb887f">cv::makePtr</a> function or corresponding static factory method if available: <div class="fragment"><div class="line"><span class="comment">// good ways</span></div><div class="line">Ptr&lt;SomeAlgo&gt; algo = makePtr&lt;SomeAlgo&gt;(...);</div><div class="line">Ptr&lt;SomeAlgo&gt; algo = SomeAlgo::create(...);</div></div><!-- fragment --> Other ways are deprecated: <div class="fragment"><div class="line"><span class="comment">// bad ways</span></div><div class="line">Ptr&lt;SomeAlgo&gt; algo = <span class="keyword">new</span> SomeAlgo(...);</div><div class="line">SomeAlgo * algo = <span class="keyword">new</span> SomeAlgo(...);</div><div class="line">SomeAlgo algo(...);</div><div class="line">Ptr&lt;SomeAlgo&gt; algo = Algorithm::create&lt;SomeAlgo&gt;(<span class="stringliteral">&quot;name&quot;</span>);</div></div><!-- fragment --></li>
<li>Algorithm properties should be accessed via corresponding virtual methods, <em>getSomeProperty/setSomeProperty</em>, generic <em>get/set</em> methods have been removed: <div class="fragment"><div class="line"><span class="comment">// good way</span></div><div class="line"><span class="keywordtype">double</span> clipLimit = clahe-&gt;getClipLimit();</div><div class="line">clahe-&gt;setClipLimit(clipLimit);</div><div class="line"><span class="comment">// bad way</span></div><div class="line"><span class="keywordtype">double</span> clipLimit = clahe-&gt;getDouble(<span class="stringliteral">&quot;clipLimit&quot;</span>);</div><div class="line">clahe-&gt;set(<span class="stringliteral">&quot;clipLimit&quot;</span>, clipLimit);</div><div class="line">clahe-&gt;setDouble(<span class="stringliteral">&quot;clipLimit&quot;</span>, clipLimit);</div></div><!-- fragment --></li>
<li>Remove <code>initModule_&lt;moduleName&gt;()</code> calls</li>
</ol>
<h2><a class="anchor" id="tutorial_transition_hints_ml"></a>
Machine learning module </h2>
<p>Since this module has been rewritten, it will take some effort to adapt your software to it. All algorithms are located in separate <em>ml</em> namespace along with their base class <em>StatModel</em>. Separate <em>SomeAlgoParams</em> classes have been replaced with a sets of corresponding <em>getProperty/setProperty</em> methods.</p>
<p>The following table illustrates correspondence between 2.4 and 3.0 machine learning classes.</p>
<table class="doxtable">
<tr>
<th>2.4 </th><th>3.0  </th></tr>
<tr>
<td>CvStatModel </td><td><a class="el" href="../../db/d7d/classcv_1_1ml_1_1StatModel.html" title="Base class for statistical models in OpenCV ML. ">cv::ml::StatModel</a> </td></tr>
<tr>
<td>CvNormalBayesClassifier </td><td><a class="el" href="../../d4/d8e/classcv_1_1ml_1_1NormalBayesClassifier.html" title="Bayes classifier for normally distributed data. ">cv::ml::NormalBayesClassifier</a> </td></tr>
<tr>
<td>CvKNearest </td><td><a class="el" href="../../dd/de1/classcv_1_1ml_1_1KNearest.html" title="The class implements K-Nearest Neighbors model. ">cv::ml::KNearest</a> </td></tr>
<tr>
<td>CvSVM </td><td><a class="el" href="../../d1/d2d/classcv_1_1ml_1_1SVM.html" title="Support Vector Machines. ">cv::ml::SVM</a> </td></tr>
<tr>
<td>CvDTree </td><td><a class="el" href="../../d8/d89/classcv_1_1ml_1_1DTrees.html" title="The class represents a single decision tree or a collection of decision trees. ">cv::ml::DTrees</a> </td></tr>
<tr>
<td>CvBoost </td><td><a class="el" href="../../d6/d7a/classcv_1_1ml_1_1Boost.html" title="Boosted tree classifier derived from DTrees. ">cv::ml::Boost</a> </td></tr>
<tr>
<td>CvGBTrees </td><td><em>Not implemented</em> </td></tr>
<tr>
<td>CvRTrees </td><td><a class="el" href="../../d0/d65/classcv_1_1ml_1_1RTrees.html" title="The class implements the random forest predictor. ">cv::ml::RTrees</a> </td></tr>
<tr>
<td>CvERTrees </td><td><em>Not implemented</em> </td></tr>
<tr>
<td>EM </td><td><a class="el" href="../../d1/dfb/classcv_1_1ml_1_1EM.html" title="The class implements the Expectation Maximization algorithm. ">cv::ml::EM</a> </td></tr>
<tr>
<td>CvANN_MLP </td><td><a class="el" href="../../d0/dce/classcv_1_1ml_1_1ANN__MLP.html" title="Artificial Neural Networks - Multi-Layer Perceptrons. ">cv::ml::ANN_MLP</a> </td></tr>
<tr>
<td><em>Not implemented</em> </td><td><a class="el" href="../../d6/df9/classcv_1_1ml_1_1LogisticRegression.html" title="Implements Logistic Regression classifier. ">cv::ml::LogisticRegression</a> </td></tr>
<tr>
<td>CvMLData </td><td><a class="el" href="../../dc/d32/classcv_1_1ml_1_1TrainData.html" title="Class encapsulating training data. ">cv::ml::TrainData</a> </td></tr>
</table>
<p>Although rewritten <em>ml</em> algorithms in 3.0 allow you to load old trained models from <em>xml/yml</em> file, deviations in prediction process are possible.</p>
<p>The following code snippets from the <code>points_classifier.cpp</code> example illustrate differences in model training process: </p><div class="fragment"><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="comment">// ======== version 2.4 ========</span></div><div class="line"><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> trainSamples, trainClasses;</div><div class="line">prepare_train_data( trainSamples, trainClasses );</div><div class="line">CvBoost  boost;</div><div class="line"><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> var_types( 1, trainSamples.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> + 1, <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga81df635441b21f532fdace401e04f588">CV_8UC1</a>, <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">Scalar</a>(CV_VAR_ORDERED) );</div><div class="line">var_types.at&lt;<a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga65f85814a8290f9797005d3b28e7e5fc">uchar</a>&gt;( trainSamples.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa3e5a47585c9ef6a0842556739155e3e">cols</a> ) = CV_VAR_CATEGORICAL;</div><div class="line">CvBoostParams  <a class="code" href="../../d1/dae/namespacecv_1_1gapi_1_1ie.html#a3ab1729bcaf2d08e30dd2bc645410908">params</a>( CvBoost::DISCRETE, <span class="comment">// boost_type</span></div><div class="line">                       100, <span class="comment">// weak_count</span></div><div class="line">                       0.95, <span class="comment">// weight_trim_rate</span></div><div class="line">                       2, <span class="comment">// max_depth</span></div><div class="line">                       <span class="keyword">false</span>, <span class="comment">//use_surrogates</span></div><div class="line">                       0 <span class="comment">// priors</span></div><div class="line">                     );</div><div class="line">boost.train( trainSamples, CV_ROW_SAMPLE, trainClasses, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(), <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(), var_types, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>(), params );</div><div class="line"></div><div class="line"><span class="comment">// ======== version 3.0 ========</span></div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;Boost&gt;</a> boost = Boost::create();</div><div class="line">boost-&gt;setBoostType(Boost::DISCRETE);</div><div class="line">boost-&gt;setWeakCount(100);</div><div class="line">boost-&gt;setWeightTrimRate(0.95);</div><div class="line">boost-&gt;setMaxDepth(2);</div><div class="line">boost-&gt;setUseSurrogates(<span class="keyword">false</span>);</div><div class="line">boost-&gt;setPriors(<a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a>());</div><div class="line">boost-&gt;train(prepare_train_data()); <span class="comment">// &#39;prepare_train_data&#39; returns an instance of ml::TrainData class</span></div></div><!-- fragment --><h2><a class="anchor" id="tutorial_transition_hints_features"></a>
Features detect </h2>
<p>Some algorithms (FREAK, BRIEF, SIFT, SURF) has been moved to <em>opencv_contrib</em> repository, to <em>xfeatures2d</em> module, <em>xfeatures2d</em> namespace. Their interface has been also changed (inherit from <code><a class="el" href="../../d0/d13/classcv_1_1Feature2D.html" title="Abstract base class for 2D image feature detectors and descriptor extractors. ">cv::Feature2D</a></code> base class).</p>
<p>List of <em>xfeatures2d</em> module classes:</p>
<ul>
<li><a class="el" href="../../d1/d93/classcv_1_1xfeatures2d_1_1BriefDescriptorExtractor.html" title="Class for computing BRIEF descriptors described in  . ">cv::xfeatures2d::BriefDescriptorExtractor</a> - Class for computing BRIEF descriptors (2.4 location: <em>features2d</em>)</li>
<li><a class="el" href="../../df/db4/classcv_1_1xfeatures2d_1_1FREAK.html" title="Class implementing the FREAK (Fast Retina Keypoint) keypoint descriptor, described in  ...">cv::xfeatures2d::FREAK</a> - Class implementing the FREAK (Fast Retina Keypoint) keypoint descriptor (2.4 location: <em>features2d</em>)</li>
<li><a class="el" href="../../dd/d39/classcv_1_1xfeatures2d_1_1StarDetector.html" title="The class implements the keypoint detector introduced by , synonym of StarDetector. : ">cv::xfeatures2d::StarDetector</a> - The class implements the CenSurE detector (2.4 location: <em>features2d</em>)</li>
<li>cv::xfeatures2d::SIFT - Class for extracting keypoints and computing descriptors using the Scale Invariant Feature Transform (SIFT) algorithm (2.4 location: <em>nonfree</em>)</li>
<li><a class="el" href="../../d5/df7/classcv_1_1xfeatures2d_1_1SURF.html" title="Class for extracting Speeded Up Robust Features from an image  . ">cv::xfeatures2d::SURF</a> - Class for extracting Speeded Up Robust Features from an image (2.4 location: <em>nonfree</em>)</li>
</ul>
<p>Following steps are needed:</p><ol type="1">
<li>Add <em>opencv_contrib</em> to compilation process</li>
<li>Include <code>opencv2/xfeatures2d.h</code> header</li>
<li>Use namespace <code>xfeatures2d</code></li>
<li>Replace <code>operator()</code> calls with <code>detect</code>, <code>compute</code> or <code>detectAndCompute</code> if needed</li>
</ol>
<p>Some classes now use general methods <code>detect</code>, <code>compute</code> or <code>detectAndCompute</code> provided by <code>Feature2D</code> base class instead of custom <code>operator()</code></p>
<p>Following code snippets illustrate the difference (from <code>video_homography.cpp</code> example): </p><div class="fragment"><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="comment">// ====== 2.4 =======</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d5/def/features2d_2features2d_8hpp.html">opencv2/features2d/features2d.hpp</a>&quot;</span></div><div class="line">BriefDescriptorExtractor brief(32);</div><div class="line">GridAdaptedFeatureDetector detector(<span class="keyword">new</span> <a class="code" href="../../df/d74/classcv_1_1FastFeatureDetector.html">FastFeatureDetector</a>(10, <span class="keyword">true</span>), DESIRED_FTRS, 4, 4);</div><div class="line"><span class="comment">// ...</span></div><div class="line">detector.detect(gray, query_kpts); <span class="comment">//Find interest points</span></div><div class="line">brief.compute(gray, query_kpts, query_desc); <span class="comment">//Compute brief descriptors at each keypoint location</span></div><div class="line"><span class="comment">// ====== 3.0 =======</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../d5/d0d/features2d_8hpp.html">opencv2/features2d.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../dc/daa/xfeatures2d_8hpp.html">opencv2/xfeatures2d.hpp</a>&quot;</span></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d3/df6/namespacecv_1_1xfeatures2d.html">cv::xfeatures2d</a>;</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;BriefDescriptorExtractor&gt;</a> brief = <a class="code" href="../../d1/d93/classcv_1_1xfeatures2d_1_1BriefDescriptorExtractor.html#ae3bc52666010fb137ab6f0d32de51f60">BriefDescriptorExtractor::create</a>(32);</div><div class="line"><a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;FastFeatureDetector&gt;</a> detector = <a class="code" href="../../df/d74/classcv_1_1FastFeatureDetector.html#ab986f2ff8f8778aab1707e2642bc7f8e">FastFeatureDetector::create</a>(10, <span class="keyword">true</span>);</div><div class="line"><span class="comment">// ...</span></div><div class="line">detector-&gt;detect(gray, query_kpts); <span class="comment">//Find interest points</span></div><div class="line">brief-&gt;compute(gray, query_kpts, query_desc); <span class="comment">//Compute brief descriptors at each keypoint location</span></div></div><!-- fragment --><h2><a class="anchor" id="tutorial_transition_hints_opencl"></a>
OpenCL </h2>
<p>All specialized <code>ocl</code> implementations has been hidden behind general C++ algorithm interface. Now the function execution path can be selected dynamically at runtime: CPU or OpenCL; this mechanism is also called "Transparent API".</p>
<p>New class <a class="el" href="../../d7/d45/classcv_1_1UMat.html">cv::UMat</a> is intended to hide data exchange with OpenCL device in a convenient way.</p>
<p>Following example illustrate API modifications (from <a href="http://opencv.org/platforms/opencl.html">OpenCV site</a>):</p>
<ul>
<li>OpenCL-aware code OpenCV-2.x <div class="fragment"><div class="line"><span class="comment">// initialization</span></div><div class="line">VideoCapture vcap(...);</div><div class="line">ocl::OclCascadeClassifier fd(<span class="stringliteral">&quot;haar_ff.xml&quot;</span>);</div><div class="line">ocl::oclMat frame, frameGray;</div><div class="line">Mat frameCpu;</div><div class="line">vector&lt;Rect&gt; faces;</div><div class="line"><span class="keywordflow">for</span>(;;){</div><div class="line">    <span class="comment">// processing loop</span></div><div class="line">    vcap &gt;&gt; frameCpu;</div><div class="line">    frame = frameCpu;</div><div class="line">    <a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab">ocl::cvtColor</a>(frame, frameGray, BGR2GRAY);</div><div class="line">    <a class="code" href="../../d6/dc7/group__imgproc__hist.html#ga7e54091f0c937d49bf84152a16f76d6e">ocl::equalizeHist</a>(frameGray, frameGray);</div><div class="line">    fd.detectMultiScale(frameGray, faces, ...);</div><div class="line">    <span class="comment">// draw rectangles …</span></div><div class="line">    <span class="comment">// show image …</span></div><div class="line">}</div></div><!-- fragment --></li>
<li>OpenCL-aware code OpenCV-3.x <div class="fragment"><div class="line"><span class="comment">// initialization</span></div><div class="line">VideoCapture vcap(...);</div><div class="line">CascadeClassifier fd(<span class="stringliteral">&quot;haar_ff.xml&quot;</span>);</div><div class="line">UMat frame, frameGray; <span class="comment">// the only change from plain CPU version</span></div><div class="line">vector&lt;Rect&gt; faces;</div><div class="line"><span class="keywordflow">for</span>(;;){</div><div class="line">    <span class="comment">// processing loop</span></div><div class="line">    vcap &gt;&gt; frame;</div><div class="line">    <a class="code" href="../../d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab">cvtColor</a>(frame, frameGray, BGR2GRAY);</div><div class="line">    <a class="code" href="../../d6/dc7/group__imgproc__hist.html#ga7e54091f0c937d49bf84152a16f76d6e">equalizeHist</a>(frameGray, frameGray);</div><div class="line">    fd.detectMultiScale(frameGray, faces, ...);</div><div class="line">    <span class="comment">// draw rectangles …</span></div><div class="line">    <span class="comment">// show image …</span></div><div class="line">}</div></div><!-- fragment --></li>
</ul>
<h2><a class="anchor" id="tutorial_transition_hints_cuda"></a>
CUDA </h2>
<p>CUDA modules has been moved into opencv_contrib repository.</p>
<ul>
<li><em>cuda</em> - <a class="el" href="../../d1/d1e/group__cuda.html">CUDA-accelerated Computer Vision</a></li>
<li><em>cudaarithm</em> - <a class="el" href="../../d5/d8e/group__cudaarithm.html">Operations on Matrices</a></li>
<li><em>cudabgsegm</em> - <a class="el" href="../../d6/d17/group__cudabgsegm.html">Background Segmentation</a></li>
<li><em>cudacodec</em> - <a class="el" href="../../d0/d61/group__cudacodec.html">Video Encoding/Decoding</a></li>
<li><em>cudafeatures2d</em> - <a class="el" href="../../d6/d1d/group__cudafeatures2d.html">Feature Detection and Description</a></li>
<li><em>cudafilters</em> - <a class="el" href="../../dc/d66/group__cudafilters.html">Image Filtering</a></li>
<li><em>cudaimgproc</em> - <a class="el" href="../../d0/d05/group__cudaimgproc.html">Image Processing</a></li>
<li><em>cudalegacy</em> - <a class="el" href="../../d5/dc3/group__cudalegacy.html">Legacy support</a></li>
<li><em>cudaoptflow</em> - <a class="el" href="../../d7/d3f/group__cudaoptflow.html">Optical Flow</a></li>
<li><em>cudastereo</em> - <a class="el" href="../../dd/d47/group__cudastereo.html">Stereo Correspondence</a></li>
<li><em>cudawarping</em> - <a class="el" href="../../db/d29/group__cudawarping.html">Image Warping</a></li>
<li><em>cudev</em> - <a class="el" href="../../df/dfc/group__cudev.html">Device layer</a></li>
</ul>
<h2><a class="anchor" id="tutorial_transition_docs"></a>
Documentation format </h2>
<p>Documentation has been converted to Doxygen format. You can find updated documentation writing guide in <em>Tutorials</em> section of <em>OpenCV</em> reference documentation (<a class="el" href="../../d4/db1/tutorial_documentation.html">Writing documentation for OpenCV</a>).</p>
<h2><a class="anchor" id="tutorial_transition_both"></a>
Support both versions </h2>
<p>In some cases it is possible to support both versions of OpenCV.</p>
<h3>Source code</h3>
<p>To check library major version in your application source code, the following method should be used: </p><div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="../../da/dd7/core_2include_2opencv2_2core_2version_8hpp.html">opencv2/core/version.hpp</a>&quot;</span></div><div class="line"><span class="preprocessor">#if CV_MAJOR_VERSION == 2</span></div><div class="line"><span class="comment">// do opencv 2 code</span></div><div class="line"><span class="preprocessor">#elif CV_MAJOR_VERSION == 3</span></div><div class="line"><span class="comment">// do opencv 3 code</span></div><div class="line"><span class="preprocessor">#endif</span></div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>Do not use <b>CV_VERSION_MAJOR</b>, it has different meaning for 2.4 and 3.x branches!</dd></dl>
<h3>Build system</h3>
<p>It is possible to link different modules or enable/disable some of the features in your application by checking library version in the build system. Standard cmake or pkg-config variables can be used for this:</p><ul>
<li><code>OpenCV_VERSION</code> for cmake will contain full version: "2.4.11" or "3.0.0" for example</li>
<li><code>OpenCV_VERSION_MAJOR</code> for cmake will contain only major version number: 2 or 3</li>
<li>pkg-config file has standard field <code>Version</code></li>
</ul>
<p>Example: </p><div class="fragment"><div class="line">if(OpenCV_VERSION VERSION_LESS &quot;3.0&quot;)</div><div class="line"># use 2.4 modules</div><div class="line">else()</div><div class="line"># use 3.x modules</div><div class="line">endif()</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:36 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
